package com.jz.utils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.http.HttpServletResponse;

/**
 * @ClassName RespJsonUtils
 * @Description 响应及json格式转换
 * @Author MR_Liu
 * @Date 2021/7/19 0019 10:22
 * @Version 1.0
 */
public class RespJsonUtils {
    public static void  objectToJson(Object obj, HttpServletResponse resp) throws Exception {
        //将对象解析成json
        ObjectMapper mapper = new ObjectMapper();
        //转json
        String json = mapper.writeValueAsString(obj);
        System.out.println(json);
        //响应
        resp.getWriter().print(json);
    }
}
